﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Schema;


using Common;

using System.Runtime.Serialization.Formatters.Binary;

namespace Client
{
    class Client
    {
        private ClientListener listener;

        public void printToScreen(Object o)
        {
            Console.WriteLine(o.ToString());
        }


        public Client()
        {
            

            try
            {
                TcpClient tcpclnt = new TcpClient();
                
                Console.WriteLine("Connecting.....");

                tcpclnt.Connect("127.0.0.1", 8001);
                // use the ipaddress as in the server program

                listener = new ClientListener(tcpclnt, this.printToScreen);
                
                Console.WriteLine("Connected");

                while (true)
                {
                    Console.WriteLine("Enter the string to be transmitted : ");
                    String str = Console.ReadLine();
                    listener.SendObject(new PlainText(str));
                    
                }
                tcpclnt.Close();
            }

            catch (Exception e)
            {
                Console.WriteLine("Error..... " + e.StackTrace);
            }

        }


        public static void Main()
        {
            Client c = new Client();
         
        }
    }
}
